package com.dms.modules.logistics.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dms.modules.logistics.entity.OrderDelivery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface OrderDeliveryMapper extends BaseMapper<OrderDelivery> {
    
    /**
     * 根据订单ID查询物流信息
     * @param orderId 订单ID
     * @return 物流信息
     */
    @Select("SELECT * FROM order_delivery WHERE order_id = #{orderId}")
    OrderDelivery getByOrderId(@Param("orderId") Long orderId);
    
    /**
     * 更新物流状态
     * @param id 物流ID
     * @param deliveryStatus 物流状态
     * @return 受影响行数
     */
    @Update("UPDATE order_delivery SET delivery_status = #{deliveryStatus}, update_time = NOW() WHERE id = #{id}")
    int updateDeliveryStatus(@Param("id") Long id, @Param("deliveryStatus") Integer deliveryStatus);
    
    /**
     * 确认收货
     * @param orderId 订单ID
     * @return 受影响行数
     */
    @Update("UPDATE order_delivery SET delivery_status = 3, receive_time = NOW(), update_time = NOW() WHERE order_id = #{orderId}")
    int confirmReceipt(@Param("orderId") Long orderId);
} 